/*
 * jxSwing Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxSwing.component.frame;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.jxSwing.component.text.PasswordField;
import org.jxSwing.component.text.TextField;
import org.jxSwing.i18n.I18N;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxSwing
 * @package org.jxSwing.component.frame
 * @date 24/05/2014 - 14:45:06
 */
public class LoginInternalFrame extends InternalFrame {
	
	private static final long serialVersionUID = -7520708731041626537L;
	
	private JPanel pnlFields;
	
	private JLabel lblUser;
	
	private TextField txtUser;
	
	private JLabel lblPassword;
	
	private PasswordField txtPassword;
	
	private JPanel pnlButtons;
	
	private JButton btnCancel;
	
	private JButton btnOK;
	
	/**
	 * @param owner
	 */
	public LoginInternalFrame(final JDesktopPane owner) {
	
		super(owner);
		
		initGUI();
	}
	
	private void initGUI() {
	
		getContentPane().setLayout(new BorderLayout(0, 0));
		getContentPane().add(getPnlFields(), BorderLayout.CENTER);
		getContentPane().add(getPnlButtons(), BorderLayout.SOUTH);
		
		setSize(350, 200);
		setClosable(true);
		setResizable(true);
		setVisible(true);
		centralize();
	}
	
	public JButton getBtnCancel() {
	
		if(btnCancel == null) {
			btnCancel = new JButton(I18N.component().cancel());
		}
		return btnCancel;
	}
	
	public JButton getBtnOK() {
	
		if(btnOK == null) {
			btnOK = new JButton(I18N.component().ok());
		}
		return btnOK;
	}
	
	public JLabel getLblPassword() {
	
		if(lblPassword == null) {
			lblPassword = new JLabel(I18N.component().password() + ":");
			lblPassword.setBounds(10, 65, 320, 25);
		}
		return lblPassword;
	}
	
	public JLabel getLblUser() {
	
		if(lblUser == null) {
			lblUser = new JLabel(I18N.component().user() + ":");
			lblUser.setBounds(10, 10, 320, 25);
		}
		return lblUser;
	}
	
	public JPanel getPnlButtons() {
	
		if(pnlButtons == null) {
			pnlButtons = new JPanel();
			pnlButtons.setLayout(new FlowLayout(FlowLayout.TRAILING, 5, 5));
			pnlButtons.add(getBtnCancel());
			pnlButtons.add(getBtnOK());
		}
		return pnlButtons;
	}
	
	public JPanel getPnlFields() {
	
		if(pnlFields == null) {
			pnlFields = new JPanel();
			pnlFields.setLayout(null);
			pnlFields.add(getLblUser());
			pnlFields.add(getTxtUser());
			pnlFields.add(getLblPassword());
			pnlFields.add(getTxtPassword());
		}
		return pnlFields;
	}
	
	public PasswordField getTxtPassword() {
	
		if(txtPassword == null) {
			txtPassword = new PasswordField();
			txtPassword.setBounds(10, 90, 320, 25);
		}
		return txtPassword;
	}
	
	public TextField getTxtUser() {
	
		if(txtUser == null) {
			txtUser = new TextField();
			txtUser.setBounds(10, 35, 320, 25);
		}
		return txtUser;
	}
}
